#ifndef LOG_DECODER_P_H
#define LOG_DECODER_P_H

#include <QtCore/QHash>
#include <QtCore/QVariant>
#include <QtCore/QThread>
#include "global.h"
#include "logmanager/log_manager.h"
#include "logdecoder/log_decoded_message.h"

namespace smsrouter {

class LogDecoder;

class LogDecoderPrivate : public QObject {
  Q_OBJECT
public:
  LogDecoderPrivate();

  ~LogDecoderPrivate();

  bool decode(const QByteArray &buff, int &pos,
              QMultiHash<int, QVariant> &parameters);

  bool decode(const QByteArray &buff, int &pos, QVariant &val);

  bool decode(const QByteArray &buff, int &pos, bool &p);

  bool decode(const QByteArray &buff, int &pos, char &p);

  bool decode(const QByteArray &buff, int &pos, int &p);

  bool decode(const QByteArray &buff, int &pos, uint &p);

  bool decode(const QByteArray &buff, int &pos, quint64 &p);

  bool decode(const QByteArray &buff, int &pos, QByteArray &p, int length);

  bool decode(const QByteArray &buff, int &pos, QString &p);

  void decode(const QString &file_name,
              quint64 start_date,
              quint64 end_date,
              quint32 &now_pos,
              quint32 start_pos,
              quint32 end_pos,
              smslog::LogLevel log_level,
              int cls,
              int obj,
              const QString &message,
              LogDecodedMessages &decoded_messages);

  LogDecodedMessages decode(quint64 start_date,
                            quint64 end_date,
                            quint32 page,
                            quint32 page_size,
                            smslog::LogLevel log_level,
                            int cls,
                            int obj,
                            const QString &message);

  QString paramToString(const QVariant &p) const;

  bool createLogMessageString(QString &message,
                              int message_id,
                              const QMultiHash<int, QVariant> &message_parameters);

signals:

  void sigDecode(binaryrpc::ServerMessage *message);

private slots:

  void decode(binaryrpc::ServerMessage *message);

private:

  friend class LogDecoder;

  QThread *thread;
};

} // namespace smsrouter

#endif // LOG_DECODER_P_H
